package com.easyWeb.config;


import com.easyWeb.context.BaseContext;
import com.easyWeb.context.constant.BaseContextConstant;
import com.easyWeb.interceptor.JwtInterceptor;
import com.easyWeb.interceptor.properties.JwtInterceptorProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@Slf4j
@EnableConfigurationProperties(JwtInterceptorProperties.class)
public class AutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public JwtInterceptor jwtInterceptor(JwtInterceptorProperties jwtInterceptorProperties) {
        log.info("正在创建Jwt拦截器");
        return new JwtInterceptor(jwtInterceptorProperties.getJwtName(), token -> { log.error("当前未配置Jwt校验工具,默认通过");return true;});
    }

    @Bean
    @ConditionalOnMissingBean
    public BaseContext<?> baseContext() {
        log.info("正在创建BaseContext");
        return new BaseContext<>(BaseContextConstant.DEFAULT_TYPE);
    }



}
